<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="lushu">
		<title>帐期设置</title>
		<script type="text/javascript" src="../script/common.js" language="JavaScript"></script>
		<script type="text/javascript" language="javascript" src="../script/common_stat.js"></script>
		<script type="text/javascript" language="JavaScript">
			var Page;//数据表格对象

			function initPageElements(){
				Eui.showNavigation();
				Page = {};//页面元素Page
				Page.form = searchForm;//form对象
				Page.columns = [];//列表项
				Page.OrgLevel = {acquirer:Constants.ORG_LEVEL_PROVINCE};//默认机构选择的截止级别
				Page.PresetOrg = {acquirer:true};//是否初始化机构控件到当前管理员所在机构
				Page.sql = "list_period";
				Page.ALLOW_OVERRIDE = false;//允许跨级复核
				Page.selection = {};
				Page.selection.status = {list:Common.getItems("period_status"),nullLabel:"全  部"};
				Eui.initDateInput("businessDateTd","帐&nbsp;&nbsp;期",Page.form.id,"businessDate","_pastDate",false);
				Clear.List.initOrganizations();//初始化受理机构和发卡机构对象
				ListPage.initFormElements();//页面select元素的初始化
				Page.columns[ListPage.COLUMNS_LENGTH_MAX] = 
					{	title:"操作",
						width:"8%",
						align:"left",
						render:operation
					};
				Page.qt = new QueryTable(Page.sql,Page.form,"datalist",Page.columns,{paramFunc:ListPage.paramFunc,exportable:true,buttons:Page.buttons});
				Page.doQuery = function(){
					ListPage.showListTable();
				}
				setPages(["listView","detailView"]);
			}
			//操作函数
			function operation(v,r){
				var s = "<a href=# onclick=\"showPeriod('"+r[1].id+"','"+r[1].name+"','"+r[1].orgLevel+"','"
					  + Format.dateRender(r[0].startDate)+"','"+Format.dateRender(r[0].endDate)+"');return false;\">明细<\/a>";
				var flag = checkable(r);
				if (flag)
					s += " <a href=# onclick=\"closePeriod('"+r[0].id+"','"
						+r[0].startDate.format('yyyy年MM月')+"','"+r[1].name+"');return false;\">关闭<\/a>";
				return s;
			}
			//检查帐期能否关闭
			function checkable(r){
				if(r[0].status!=PeriodStatus.OPEN)
					return false;
				if (Format.dateRender(r[0].endDate) >= Format.today())
					return false;
				var currentOrg = Common.cOrg();
				return r[1].id==currentOrg.id 
					||(Page.ALLOW_OVERRIDE && r[1]["p"+currentOrg.orgLevel]==currentOrg.id );
			}
			//关闭帐期
			function closePeriod(id,period,orgName){
				var info="确认关闭【"+orgName+"】的【"+period+"】的帐期?";
				if(showQuestion(info)){
					DWR.call("periodService.closePeriod",
							id,
							function(result){
								showInformation("保存成功");
								Page.doQuery();
							},
							{blockScreen:true}
						);
				}
			}
			//显示明细
			function showPeriod(orgID,orgName,orgLevel,startDate,endDate){
				switchPage('detailView');
				if (!Page.subPageInit){
					Page.subPage = {};
					Page.subPage.sql = "daily_list_city";
					Page.subPage.form = $('periodForm');
					Common.initDict(Page.subPage.form.type,
							Common.getSubsetItems("daily_check_type",Clear.DailyCheck.PERIOD_TYPE),"全  部");
					Common.initDict(Page.subPage.form.status,
							Common.getSubsetItems("daily_status",Clear.DailyCheck.PERIOD_STATUS),"全  部");
					//Page.subPage.form.status.value= DailyCheckStatus.UNCHECKED;
					
					Page.subPage.qt = new QueryTable(Page.subPage.sql,Page.subPage.form,"detailPeriod",[],{exportable:true});
					Page.subPage.doQuery = function(){
						Page.subPage.qt.showTable();
					}
					Page.subPageInit = true;
				}
				Page.subPage.form.acquirerID.value=orgID;
				Page.subPage.form.acquirerName.value=orgName;
				Page.subPage.form.acquirerLevel.value=orgLevel;
				var arys = startDate.split('-');
				var start = new Date(arys[0],arys[1]-1,arys[2]); 
				Page.subPage.form.period.value=start.format('yyyy年MM月');
				Page.subPage.form.startDate.value=startDate;
				Page.subPage.form.endDate.value=endDate;
				Page.subPage.doQuery();
			}
		</script>
	</head>
	<body onload="initPageElements()">
		<div class="nav"><div id="nav">&nbsp;</div></div>
		
		<div id="listView">
			<form id="searchForm" name="searchForm">
				<div class="searchForm">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0">
						<tr>
							<td id="acquirer"></td>
							<td id="businessDateTd"></td>
							<td>
								<label>帐期状态</label>
								<select name="status"><option></option></select>
							</td>
							<td><button onclick="Page.doQuery();">查 询</button></td>
						</tr>
					</table>
				</div>
			</form>
			<div id="datalist"></div>
		</div>
		
		<div id="detailView" style="display:none">
			<form id="periodForm" name="periodForm">
				<input type="hidden" name="acquirerID">
				<input type="hidden" name="acquirerLevel">
				<div class="searchForm">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0">
						<tr>
							<td>
								<label>当前机构</label>
								<input type="text" name="acquirerName" readonly class="readonly">
							</td>
							<td>
								<label>帐&nbsp;&nbsp;&nbsp;&nbsp;期</label>
								<input type="text" name="period" readonly class="readonly">
							</td>
							<td class="label4">
								<label>日结类型</label>
								<select name="type"><option></option></select>
							</td>
							<td></td>
						</tr>
						<tr>
							<td>
								<label>起始日期</label>
								<input type="text" name="startDate" readonly class="readonly">
							</td>
							<td>
								<label>结束日期</label>
								<input type="text" name="endDate" readonly class="readonly">
							</td>
							<td class="label4">
								<label>日结状态</label>
								<select name="status"><option></option></select>
							</td>
							<td><button onclick="Page.subPage.doQuery();">查 询</button></td>
						</tr>
					</table>
				</div>
			</form>
			<div id="detailPeriod"></div>
			<p>
				<button onclick="switchPage('listView')">返 回</button>
			</p>
		</div>
	</body>
</html>